package com.hhhn.wk.main.tab4.allorder.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


import com.bumptech.glide.Glide;
import com.hhhn.wk.R;
import com.hhhn.wk.main.tab4.allorder.entity.ItemGoodsBean;
import com.hhhn.wk.utils.Constants;

import java.util.List;


public class ChildAdapter extends BaseAdapter {
	private List<ItemGoodsBean> list;
	private Context context;
	private LayoutInflater inflater;

	public ChildAdapter(Context context) {
		super();
		this.context = context;
	}
	public void addAll(List<ItemGoodsBean> list) {
		this.list=list;
		notifyDataSetChanged();
	}
	public void clearAll() {
		this.list.clear();
		notifyDataSetChanged();
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}
	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}
	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ParentListItem parentListItem = null;
		if (convertView == null) {
			parentListItem = new ParentListItem();
		    inflater = LayoutInflater.from(context);
			convertView = inflater.inflate(R.layout.item_order_within, null, false);

			parentListItem.tv_goodsImg = convertView .findViewById(R.id.tv_goodsImg);
			parentListItem.tv_goodsName =  convertView .findViewById(R.id.tv_goodsName);
			parentListItem.tv_goodsMoney = (TextView) convertView .findViewById(R.id.tv_goodsMoney);
			parentListItem.tv_goodsNumber = (TextView) convertView .findViewById(R.id.tv_goodsNumber);
			convertView.setTag(parentListItem);
		} else {
			parentListItem = (ParentListItem) convertView.getTag();
		}
		parentListItem.tv_goodsName.setText(list.get(position).getGoodsName());
		parentListItem.tv_goodsMoney.setText("￥"+list.get(position).getGoodsMoney());
		parentListItem.tv_goodsNumber.setText("X"+list.get(position).getGoodsNumber());
		Glide.with(context).load(Constants.HTTPIMG+list.get(position).getGoodsImg()).into(parentListItem.tv_goodsImg);
		return convertView;
	}
	public class ParentListItem {
		ImageView tv_goodsImg;//商品图标
		TextView tv_goodsName, tv_goodsMoney, tv_goodsNumber;
	}

}
